package it.canraid.leaflet.control;

import it.canraid.leaflet.R;
import it.canraid.leaflet.model.ReadMessagePill;
import it.canraid.leaflet.view.StatusMessageView;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

/**
 * @deprecated
 * 
 * @author evitcam
 * 
 */
public class MessageListAdapter extends ArrayAdapter<ReadMessagePill> {
    private Activity context = null;
    private List<ReadMessagePill> values = new ArrayList<ReadMessagePill>();

    public MessageListAdapter(Activity context, int textViewResourceId) {
	super(context, textViewResourceId);
	this.context = context;
    }

    public View getView(int pos, View cacheView, ViewGroup parent) {
	ReadMessagePill readMessagePill = values.get(pos);
	if (readMessagePill.itemView == null) {
	    LayoutInflater inflater = context.getLayoutInflater();
	    readMessagePill.itemView = inflater.inflate(R.layout.item_v, null);
	    // readMessagePill.messageView = (ReadMessageView)
	    // readMessagePill.itemView.findViewById(R.id.readMessageView);
	    readMessagePill.statusView = (StatusMessageView) readMessagePill.itemView.findViewById(R.id.statusMessageView);
	}
	// readMessagePill.refresh();

	return readMessagePill.itemView;
    }

    public void set(List<ReadMessagePill> values) {
	if (values != null) {
	    synchronized (this.values) {
		this.values = values;
		clear();
		addAll(values);
		notifyDataSetChanged();
	    }
	}
    }

    public List<ReadMessagePill> get() {
	List<ReadMessagePill> aux = new ArrayList<ReadMessagePill>();
	synchronized (values) {
	    Iterator<ReadMessagePill> iter = values.iterator();
	    while (iter.hasNext())
		aux.add(iter.next());
	}
	return aux;
    }

}
